<?php

class RegisterController extends AbstractController {

	public function indexAction() {
		$this->template('index/register.phtml');
	}

	public function submitAction() {
		$member = $this->getRequest()->getPost('member');
		if ($member['loginName'] == '') {
			$this->showMsg('登录账号未输入');
		}
		if ($member['memberName'] == '') {
			$member['memberName'] = $member['loginName'];
		}
		if ($member['password'] != $member['password2']) {
			$this->showMsg('两次密码输入的不一致');
		}
		$find = DbMembersModel::getByLoginName($member['loginName']);
		if ($find) {
			$this->showMsg('登录账号重复，请更换');
		}
		DbMembersModel::addData(
			array(
				'memberName' => $member['memberName'],
				'loginName' => $member['loginName'],
				'password' => $this->genPassword($member['password']),
				'createTime' => $this->now(),
			)
		);
		$this->showMsg('注册成功', $this->getURI(''));
	}

}